﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UT_AMS_UI_Controls
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //grid.Dock = DockStyle.Fill;

            // init gv
            AMS.UI.Controls.AmsGridView gv = grid.GridView;
            gv.ShowCheckBoxes = true;
            //string names = "Name|Sex|Age|Status|";
            //string captions = "姓名|性别|年龄|状态|";
            //gv.Init(names, captions);

            //grid.Init("UserManager");

            //DoDataBind();
        }

        DataTable dt = new DataTable();
        void DoDataBind()
        {
            grid.Preload();
            if (dt.Columns.Count == 0)
            {
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Sex", typeof(string));
                dt.Columns.Add("Age", typeof(string));
                dt.Columns.Add("Status", typeof(string));
                dt.Columns.Add("Notes", typeof(string));
            }

            for (int i = 0; i < 1000; i++)
            {
                dt.Rows.Add("xiaoming", "1", "25", "unmarried" + i.ToString(), "现金管理子系统交易改动只涉及到头文件添加");
                dt.Rows.Add("xiaoming", "0", "25", "unmarried", "对外发布的接口；因此只需要使用现金管理客户端");
                dt.Rows.Add("xiaoming", "1", "25", "unmarried", "管理专线客户连接到相关的测试环境，并使用正");
                dt.Rows.Add("xiaoming", "0", "25", "unmarried", "交易，使用付款方账户“河北省|876001040020090|基本存");
                dt.Rows.Add("xiaoming", "1", "25", "unmarried", "金额1.5元。提交后提示交易成功");
            }

            dt.DefaultView.AllowNew = false;
            dt.DefaultView.AllowEdit = false;
            dt.DefaultView.AllowDelete = false;

            grid.DataBind(dt);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dt.Rows[int.Parse(txtRow.Text)][int.Parse(txtColumn.Text)] = txtValue.Text;
        }

        private void btnDataBind_Click(object sender, EventArgs e)
        {
            string names = "Name|Sex|Age|Status|Notes|";
            string captions = "姓名|性别|年龄|状态|备注|";
            //grid.GridView.DataBind(null);
            //grid.GridView.Rows.Clear();
            if (grid.GridView.Columns.Count == 0)
            {
                grid.GridView.Init(names, captions);
            }

            DoDataBind();
        }

        private void btnBindObjectList_Click(object sender, EventArgs e)
        {
            List<UserInfo> users = new List<UserInfo>();

            for (int i = 0; i < 200; i++)
            {
                UserInfo user = new UserInfo();
                user.Name = "xiaoming";
                user.Sex = 0;
                user.Age = 25;
                user.Status = "married";
                user.Notes = "ktfrddhhjkjfhas;j";
                users.Add(user);
            }

            string names = "Name|Sex|Age|Status|Notes|";
            string captions = "姓名|性别|年龄|状态|备注|";
            if (grid.GridView.Columns.Count == 0)
            {
                grid.GridView.Init(names, captions);
            }

            grid.DataBind(users);
        }

        private void btnLoadFromConfig_Click(object sender, EventArgs e)
        {
            grid.Init("UserManager");
            DoDataBind();
        }
    }
}
